package com.jiyun.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jiyun.dto.LunbotuDto;
import com.jiyun.mapper.lunbotuMapper;
import com.jiyun.model.xitong.Lunbotu;
import com.jiyun.result.Result;
import com.jiyun.result.ResultCodeEnum;
import com.jiyun.service.lunbotuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class lunbotuServiceImpl extends ServiceImpl<lunbotuMapper, Lunbotu> implements lunbotuService {
@Autowired
private lunbotuMapper lunbotuMapper;
    @Override
    public Result findAll(LunbotuDto lunbotuDto, Integer pn, Integer ps) {
        Page<Lunbotu> page = new Page<>();
        QueryWrapper<Lunbotu> w = new QueryWrapper<>();
        if (lunbotuDto.getMin()!=null&&lunbotuDto.getMax()!=null){
            w.between("fabudate",lunbotuDto.getMin(),lunbotuDto.getMax());
        }
        if (lunbotuDto.getName()!=null&&lunbotuDto.getName()!=""){
            w.like("name",lunbotuDto.getName());
        }
        w.orderByDesc("paixu");
        List<Lunbotu> list = lunbotuMapper.selectList(w);
        page.setRecords(list);
        page.setTotal(list.size());
        return Result.build(page, ResultCodeEnum.SUCCESS);
    }

    @Override
    public void updateStatus(Integer id) {
        Lunbotu lunbotu = lunbotuMapper.selectById(id);
        if (lunbotu.getStatus()){
            lunbotu.setStatus(false);
        }else {
            lunbotu.setStatus(true);
        }
        lunbotuMapper.updateById(lunbotu);
    }
}
